<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Ajax extends MY_Controller {
// Some code happens here
    public function __construct()
    {
        parent:: __construct();
        $this->load->model('binhluan');
        $this->load->library('parser');
        $this->load->library('utils');  
    }
   public function comment()
   {
   $name =$this->input->post('name');
   $email=$this->input->post('email');
   $comment=strip_tags($this->input->post('body'));
   $idSP=$this->input->post('id');

    //$date =date();
    $date = date('Y-m-d');
    $data['name'] = $name;
    $data['ngaytao'] = $date;
    $data['noidung'] = $comment;
    $this->binhluan->add_comment($idSP,$name,$email,$comment,$date);
    return $this->parser->parse('comment/a_comment',$data,false);
   }
    public function comment_all()
   {
       $idSP=$this->input->post('id');
       
       $data['binhluan'] = ""  ; 
       $comts = $this->binhluan->get_all($idSP); 
       $data_comment['list_comment'] = "";
       foreach($comts as $comment)
       {
            $cmt['name'] = $comment->Name;
            $cmt['ngaytao'] = $comment->NgayTao;
            $cmt['noidung'] = $comment->text;
            $data_comment['list_comment'] .= $this->parser->parse('comment/a_comment',$cmt,true);
        } 
        echo $data_comment['list_comment'];
   }
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */